/*************************************************************************
	> File Name: Memento.cc
	> Author: Joker
	> Mail: mahongtao@foxmail.com 
	> Created Time: 2020-09-23 11:46:15
 ************************************************************************/

#include "Memento.h"

#include <iostream>
 
using std::cout;
using std::endl;

/**************************
 *Originator
 * ***********************/
Originator::Originator(){
    cout << "Originator()" << endl;
}

Originator::Originator(const STATE & State)
    :_State(State)
{
    cout << "Originator(const STATE &)" << endl;
}

Originator::~Originator(){
    cout << "~Originator()" << endl;
}

STATE Originator::GetState(){
    return _State;
}

void Originator::SetState(const STATE & State){
    _State = State;
}

Memento * Originator::CreateMemento(){
    return new Memento(_State);
}

void Originator::RestoreState(Memento * pMemento){
    if(nullptr != pMemento){
        _State = pMemento->GetState();
    }
}

void Originator::PrintState(){
    cout << "State = " << _State << endl;
}

/******************************
 *Memento
 * ***************************/
Memento::Memento(const STATE & State)
    :_State(State)
{
    cout << "Memento(const STATE &)" << endl;
}

STATE Memento::GetState(){
    return _State;
}

void Memento::SetState(const STATE & State){
    _State = State;
}
